package com.guoxin.thread.concurrent.chapter9;

import java.util.stream.Stream;

public class DifferenceOfSleepAndWait {
    private static final Object LOCK = new Object();

    public static void main(String[] args) {
        new Thread("M1") {
            @Override
            public void run() {
//               m1();
                m2();
            }
        }.start();

        new Thread("M2") {
            @Override
            public void run() {
//                m1();
                m2();
            }
        }.start();

    }

    public static void m1() {
        synchronized (LOCK) {
            try {
                System.out.println(Thread.currentThread().getName());
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void m2() {
        synchronized (LOCK) {
            try {
                System.out.println(Thread.currentThread().getName() + ">> m2");
                LOCK.wait(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
